using AutoMapper;
using StudentVideo.Data.Entities;
using StudentVideo.Shared.Dtos.Student;

namespace StudentVideo.Mapping;

public class StudentMapping: Profile {
   public StudentMapping() {
      CreateMap<StudentCreateRequest, StudentEntity>()
         .ForMember(dest => dest.Password, opt => opt.Ignore())
         .ForMember(dest => dest.StudentId, opt => opt.MapFrom(src => src.Id))
         .ForMember(dest => dest.Phone, opt => opt.MapFrom(src => src.Telephone))
         .ForMember(dest => dest.EnrollmentDate, opt => opt.MapFrom(src => DateTime.Parse(src.Enrollment)))
         .ForAllMembers(opt => opt.Condition((src, dest, srcMember) => srcMember != null));

      CreateMap<StudentEntity, StudentFindResultItem>()
         .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.StudentId))
         .ForMember(dest => dest.SchoolYear, opt => opt.MapFrom(src => src.Grade))
         .ForMember(dest => dest.Enrollment, opt => opt.MapFrom(src => src.EnrollmentDate))
         .ForMember(dest => dest.Graduation, opt => opt.MapFrom(src => src.GraduationDate))
         .ForAllMembers(opt => opt.Condition((src, dest, srcMember) => srcMember != null));
   }
}
